Skip to content

Define the shared code once in @onload instead of in every block - #23

Merged
cedricvogel-leo merged 1 commit into
mainfrom
fix/shared-code-onload
Oct 26, 2026
Merged

cedricvogel-leo merged 1 commit into
mainfrom
fix/shared-code-onload

Conversation

@cedricvogel-leo

Copy link
Copy Markdown
Collaborator

Problem

Slides that use glpython blocks and a choice quiz hang in Chrome on the loading screen when they are opened directly, e.g. Etappe 1 of glpython-edu/funktionen at …/README.md#18 (also after a reload, since LiaScript keeps the slide in the URL). Safari works.

Console: Invalid regular expression: /^ …39408 spaces… /g: Regular expression too large.

Cause: LiaScript expands macros into the remaining input, but the parser library computes the column against the original text (currentLocation in andre-dietrich/parser-combinators). Once the expansions run past the end of the original text, the column is the overshoot. The choice-quiz parser (Quiz/Vector/Parser.elm, item) pushes that many spaces as indentation, and V8 refuses the resulting regex (Safari's engine accepts it). Every glpython block expanded to ~37k characters, 34k of them the run-once session logic, so a slide with one or two blocks was enough.

Change

  • The session logic is now window.__glpythonMount(args, send) in the template's @onload, which LiaScript runs once per course (an imported template's @onload is appended to the course's).
  • The run-once block only passes ["@0" … "@9"] and its send. A block that runs before @onload waits in window.__glpythonPending, which @onload empties.
  • One expansion of @GLPython.embed goes from 37,048 to 2,964 characters.
  • check-macro also checks the @onload block (node --check, same line reporting).
  • CLAUDE.md: where the code lives and why it must stay in @onload.

The code itself is unchanged, apart from sessionId, mode and the options coming from args.

Tested

Headless Chrome, hosted player (liascript.github.io/course):

Not tested: turtle, Tests, the IDE link, and iPad.

Follow-up

The real bug is in LiaScript; to be reported upstream with a minimal course.

🤖 Generated with Claude Code

LiaScript expands a macro into every slide that uses it. With the whole
session logic in the run-once block, every glpython block added about 37k
characters, and slides with a choice quiz hung in Chrome when opened
directly (e.g. course/?…README.md#18): LiaScript's parser computes the
column against the original text, the expansions push it far past the end,
the quiz parser builds an indentation regex of ~39k spaces, and V8 throws
"Regular expression too large" (Safari's engine accepts it).

The session logic is now window.__glpythonMount in @onload. The run-once
block only passes its arguments and send; a block that runs before
@onload waits in window.__glpythonPending. One expansion is now ~3k
characters. check-macro also checks the @onload block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant